﻿using System;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Messaging;

namespace AspectIntercept
{
    public class InterceptProperty : IContextProperty, IContributeObjectSink
    {
        public Boolean InterceptAllMethods { get; set; }
        public Type PreProcesor { get; set; }
        public Type PostProcesor { get; set; }
        public String[] OmitMethods { get; set; }

        public InterceptProperty()
            : base()
        {
        }

        #region IContextProperty Members

        public string Name
        {
            get
            {
                return "Intercept";
            }
        }

        public bool IsNewContextOK(Context newCtx)
        {
            InterceptProperty p = newCtx.GetProperty("Intercept") as InterceptProperty;
            if (p == null)
                return false;
            return true;
        }

        public void Freeze(Context newContext)
        {
        }

        #endregion

        #region IContributeObjectSink Members

        public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink)
        {
            return new InterceptSink(nextSink) { InterceptAllMethods = InterceptAllMethods, PostProcesor = PostProcesor, PreProcesor = PreProcesor, OmitMethods = OmitMethods };
        }

        #endregion
    }

}
